package com.b2bpsssm.service.impl;
//    收款单表


import com.b2bpsssm.common.R;
import com.b2bpsssm.mapper.ReceiptMapper;
import com.b2bpsssm.pojo.SalesPassOrder;
import com.b2bpsssm.service.ReceiptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReceiptServiceImpl implements ReceiptService {
    @Autowired
    private ReceiptMapper receiptMapper;


          //查询付款单数据
    @Override
    public R queryReceiptList(Integer currentPage, Integer pageSize) {
        R r = new R();
        Integer start = (currentPage - 1) * pageSize;//分页第一个参数
        Integer off = pageSize; //分页第二个参数

        //查询后的数据
        List<SalesPassOrder> receiptList = receiptMapper.queryReceiptList(start, off);

        //成功后返回的结果
        r.setCode(200);
        r.setMassage("success");
        r.setData(receiptList);
        return r;
    }
         //根据单据编号查询具体数据
        @Override
        public R queryReceiptByNumber(String document_no) {
            R r = new R();
            List<SalesPassOrder> number = receiptMapper.queryReceiptByNumber(document_no);
            r.setMassage("success");
            r.setData(number);
            r.toString();
            r.setCode(200);
            return  r;

    }
    //  根据付款方查询具体的数据
    @Override
    public R queryReceiptByPayer(Integer currentPage, Integer pageSize, String customer) {
        R r = new R();
        Integer start = (currentPage - 1) * pageSize;//分页第一个参数
        Integer off = pageSize; //分页第二个参数
        List<SalesPassOrder> payer = receiptMapper. queryReceiptByPayer(start, off,customer);
        r.setMassage("success");
        r.setData(payer);
        r.setCode(200);
        r.toString();
        return  r;
    }


     //新增收款单
    public R addReceipt(SalesPassOrder salesPassOrder) {
            R r = new R();
            try {
        int result = receiptMapper.addReceipt(salesPassOrder);
        if (result > 0) {
            r.setCode(200);
            r.setMassage("添加成功");
        }
    } catch (Exception e) {
        e.printStackTrace();
        r.setCode(500);
        r.setMassage("系统开小差了，请联系管理员！");
    }
            return r;

}
       //  以付款方关键字 时间范围 进行关键字查询
    @Override
    public R selReceiptLikeReceiptPayer(Integer currentPage, Integer pageSize, String sub_date1, String sub_date2, String  customer) {
        R r = new R();
        Integer start = (currentPage - 1) * pageSize;//分页第一个参数
        Integer off = pageSize; //分页第二个参数
        List<SalesPassOrder> list = receiptMapper.selReceiptLikeReceiptPayer(start, off, sub_date1, sub_date2,customer);
        //成功后返回的结果
        r.setCode(200);
        r.setMassage("success");
        r.setData(list);

        return r;
    }

}
